﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;
using YArchitech.Revit;

namespace YArchitech.HVAC
{
	public class RadiatorConnHelper
	{
		public RadiatorConnHelper(Document doc, Selection sel)
		{
			this.doc = doc;
			this.sel = sel;
		}

		public bool SelectElementSet()
		{
			string text = "请选择需连接的散热器及其相应的水管……";
			List<Element> list = null;
			for (;;)
			{
				list = new List<Element>();
				if (this.Sel.GetElementIds().Count > 0)
				{
					foreach (ElementId elementId in this.Sel.GetElementIds())
					{
						list.Add(this.Doc.GetElementById(elementId));
					}
					this.Message = this.ValidatingElements(list);
					if (string.IsNullOrEmpty(this.Message))
					{
						break;
					}
					YJKMessageBox.Information(this.Message);
					RevitVersionFuncs.ClearSelection(this.Sel);
				}
				else
				{
					HYRadiatorAndPipeFilter hyradiatorAndPipeFilter = new HYRadiatorAndPipeFilter();
					list = this.Sel.PickElementsByRectangle(hyradiatorAndPipeFilter, text).ToList<Element>();
					this.Message = this.ValidatingElements(list);
					if (string.IsNullOrEmpty(this.Message))
					{
						goto IL_F0;
					}
					YJKMessageBox.Information(this.Message);
					RevitVersionFuncs.ClearSelection(this.Sel);
				}
			}
			bool result = true;
			goto IL_F2;
			IL_F0:
			result = true;
			IL_F2:
			this.GetConningPipes();
			return result;
		}

		private void GetConningPipes()
		{
			if (this.ConnStyle == 1 && this.ListPipe.Count > 1)
			{
				this.supplyPipe = null;
				this.returnPipe = null;
				foreach (Pipe pipe in this.ListPipe)
				{
					if (this.JudgePipingSystem(pipe) == 1)
					{
						this.supplyPipe = pipe;
					}
					if (this.JudgePipingSystem(pipe) == 2)
					{
						this.returnPipe = pipe;
					}
				}
				if (this.supplyPipe != null)
				{
					this.ListPipe.Remove(this.supplyPipe);
				}
				if (this.returnPipe != null)
				{
					this.ListPipe.Remove(this.returnPipe);
				}
				if (this.supplyPipe == null && this.ListPipe.Count > 0)
				{
					this.supplyPipe = this.ListPipe[0];
					this.ListPipe.Remove(this.supplyPipe);
				}
				if (this.returnPipe == null && this.ListPipe.Count > 0)
				{
					this.returnPipe = this.ListPipe[0];
				}
				if (this.returnPipe != null && this.supplyPipe == null)
				{
					this.supplyPipe = this.returnPipe;
					return;
				}
			}
			else if (this.ListPipe.Count > 0)
			{
				foreach (Pipe pipe2 in this.ListPipe)
				{
					if (this.JudgePipingSystem(pipe2) == 1)
					{
						this.supplyPipe = pipe2;
					}
				}
				if (this.supplyPipe == null)
				{
					this.supplyPipe = this.ListPipe[0];
				}
			}
		}

		private int JudgePipingSystem(Pipe pipe)
		{
			int result = 0;
			PipeSystemType pipeSystemType = new YJKPiping<Pipe>(pipe).GetConnectorPipingSystemType().pipeSystemType;
            if (pipeSystemType == (PipeSystemType)7)
			{
				result = 1;
			}
            else if (pipeSystemType == (PipeSystemType)8)
			{
				result = 2;
			}
			return result;
		}

		private Connector GetConnector(FamilyInstance fiRadiator, int styleNum)
		{
			Connector result = null;
			foreach (Connector connector in YJKRevitTools.GetElementConnector(fiRadiator, (Autodesk.Revit.DB.Domain)3))
			{
                if (styleNum == 1 && connector.PipeSystemType == (PipeSystemType)7)
				{
					result = connector;
				}
                if (styleNum == 2 && connector.PipeSystemType == (PipeSystemType)8)
				{
					result = connector;
				}
			}
			return result;
		}

		private void GetConnecctor(FamilyInstance fiRadiator, ref Connector inConn, ref Connector outConn)
		{
			List<Connector> elementConnector = YJKRevitTools.GetElementConnector(fiRadiator, (Autodesk.Revit.DB.Domain)3);
			if (elementConnector.Count < 2)
			{
				return;
			}
			Parameter parameter = fiRadiator.GetParameter("HYRadiatorType");
			if (parameter == null)
			{
				return;
			}
			string text = parameter.AsString();
			uint num = 0;//<PrivateImplementationDetails>.ComputeStringHash(text);
			if (num <= 2279835011u)
			{
				if (num <= 518729469u)
				{
					if (num != 401286136u)
					{
						if (num != 501951850u)
						{
							if (num != 518729469u)
							{
								goto IL_26C;
							}
							if (!(text == "13"))
							{
								goto IL_26C;
							}
						}
						else
						{
							if (!(text == "12"))
							{
								goto IL_26C;
							}
							goto IL_200;
						}
					}
					else if (!(text == "14"))
					{
						goto IL_26C;
					}
				}
				else if (num != 2247118416u)
				{
					if (num != 2263057392u)
					{
						if (num != 2279835011u)
						{
							goto IL_26C;
						}
						if (!(text == "42"))
						{
							goto IL_26C;
						}
						goto IL_1EB;
					}
					else
					{
						if (!(text == "43"))
						{
							goto IL_26C;
						}
						goto IL_236;
					}
				}
				else
				{
					if (!(text == "32"))
					{
						goto IL_26C;
					}
					goto IL_1EB;
				}
			}
			else if (num <= 2314375987u)
			{
				if (num != 2296612630u)
				{
					if (num != 2297451273u)
					{
						if (num != 2314375987u)
						{
							goto IL_26C;
						}
						if (!(text == "24"))
						{
							goto IL_26C;
						}
					}
					else
					{
						if (!(text == "31"))
						{
							goto IL_26C;
						}
						goto IL_1EB;
					}
				}
				else
				{
					if (!(text == "41"))
					{
						goto IL_26C;
					}
					goto IL_1EB;
				}
			}
			else if (num != 2347784130u)
			{
				if (num != 2364708844u)
				{
					if (num != 2398264082u)
					{
						goto IL_26C;
					}
					if (!(text == "23"))
					{
						goto IL_26C;
					}
				}
				else
				{
					if (!(text == "21"))
					{
						goto IL_26C;
					}
					goto IL_236;
				}
			}
			else
			{
				if (!(text == "34"))
				{
					goto IL_26C;
				}
				goto IL_200;
			}
			inConn = this.GetConnector(elementConnector, 0);
			outConn = this.GetConnector(elementConnector, 1);
			return;
			IL_1EB:
			inConn = this.GetConnector(elementConnector, 1);
			outConn = this.GetConnector(elementConnector, 0);
			return;
			IL_200:
			parameter = fiRadiator.GetParameter("HYRadiatorVector");
			if (parameter == null)
			{
				return;
			}
			text = parameter.AsString();
			XYZ pointValue = this.GetPointValue(text);
			inConn = this.GetConnector(elementConnector, pointValue, 0);
			outConn = this.GetConnector(elementConnector, pointValue, 1);
			return;
			IL_236:
			parameter = fiRadiator.GetParameter("HYRadiatorVector");
			if (parameter == null)
			{
				return;
			}
			text = parameter.AsString();
			pointValue = this.GetPointValue(text);
			inConn = this.GetConnector(elementConnector, pointValue, 1);
			outConn = this.GetConnector(elementConnector, pointValue, 0);
			return;
			IL_26C:
			inConn = elementConnector[0];
			outConn = elementConnector[1];
		}

		private XYZ GetPointValue(string typeValue)
		{
			string[] array = typeValue.Substring(1, typeValue.Length - 2).Split(new char[]
			{
				','
			});
			return new XYZ(Convert.ToDouble(array[0]), Convert.ToDouble(array[1]), Convert.ToDouble(array[2]));
		}

		private Connector GetConnector(List<Connector> listConn, int pntNum = 0)
		{
			Connector result = null;
			XYZ origin = listConn[0].Origin;
			XYZ origin2 = listConn[1].Origin;
			if (pntNum == 0)
			{
				if (origin.Z > origin2.Z)
				{
					result = listConn[0];
				}
				else
				{
					result = listConn[1];
				}
			}
			if (pntNum == 1)
			{
				if (origin.Z > origin2.Z)
				{
					result = listConn[1];
				}
				else
				{
					result = listConn[0];
				}
			}
			return result;
		}

		private Connector GetConnector(List<Connector> listConn, XYZ baseVector, int pntNum = 0)
		{
			Connector result = null;
			XYZ origin = listConn[0].Origin;
			XYZ xyz = listConn[1].Origin.Subtract(origin).Normalize();
			if (pntNum == 0)
			{
				if (baseVector.IsAlmostEqualTo(xyz, 0.0001))
				{
					result = listConn[0];
				}
				else
				{
					result = listConn[1];
				}
			}
			if (pntNum == 1)
			{
				if (baseVector.IsAlmostEqualTo(xyz, 0.0001))
				{
					result = listConn[1];
				}
				else
				{
					result = listConn[0];
				}
			}
			return result;
		}

		public bool ConnectRadiatorSet(XYZ basePnt)
		{
			bool result = true;
			if (this.ConnStyle == 1)
			{
				if (this.SupplyPipe == null || this.ReturnPipe == null)
				{
					result = false;
					this.message = "连接管道不能为空！";
					return result;
				}
				if (YJKRevitTools.isRiserPipe(this.SupplyPipe) && YJKRevitTools.isRiserPipe(this.ReturnPipe))
				{
					result = this.ConnRiserRadiator();
				}
				else if (!YJKRevitTools.isRiserPipe(this.SupplyPipe) && !YJKRevitTools.isRiserPipe(this.ReturnPipe))
				{
					result = this.ConnRadiators(basePnt);
				}
				else
				{
					result = false;
					this.message = "选择的管道应同为立管或水平管！";
				}
			}
			else
			{
				if (this.SupplyPipe == null)
				{
					result = false;
					this.message = "连接管道不能为空！";
					return result;
				}
				if (YJKRevitTools.isRiserPipe(this.SupplyPipe))
				{
					result = this.ConnRiserRadiator();
				}
				else if (!YJKRevitTools.isRiserPipe(this.SupplyPipe))
				{
					result = this.ConnRadiators(basePnt);
				}
			}
			return result;
		}

		public bool ConnRiserRadiator()
		{
			bool result = true;
			RadiatorConnParam radiatorConnParam = this.InitialRadiatorParam(this.ListRadiator[0]);
			if (radiatorConnParam.InConnector == null || radiatorConnParam.OutConnector == null)
			{
				throw new Exception("未能找到连接用的进口或出口连接件，请检查散热器族，\n或者用布置散热器重新布置族！");
			}
			RadiatorConnParam radiatorConnParam2 = this.CreatLeadPipe(radiatorConnParam);
			if (radiatorConnParam2 == null)
			{
				return false;
			}
			if (this.ConnStyle == 1)
			{
				result = this.ConnDoublePipes(radiatorConnParam2);
			}
			if (this.ConnStyle == 2)
			{
				result = this.ConnDownPipes(radiatorConnParam2);
			}
			if (this.ConnStyle == 3)
			{
				result = this.ConnCrossPipes(radiatorConnParam2);
			}
			return result;
		}

		public bool ConnRadiators(XYZ basePnt)
		{
			bool result = true;
			List<RadiatorConnParam> list = this.InitialRadiatorParam(this.ListRadiator);
			List<RadiatorConnParam> list2 = new List<RadiatorConnParam>();
			foreach (RadiatorConnParam radiatorConnParam in list)
			{
				if (radiatorConnParam.InConnector != null && radiatorConnParam.OutConnector != null)
				{
					list2.Add(radiatorConnParam);
				}
			}
			if (list2.Count < 1)
			{
				throw new Exception("未能找到连接用的进口或出口连接件，请检查散热器族，\n或者用布置散热器重新布置族！");
			}
			List<RadiatorConnParam> list3 = this.CreatLeadPipe(list2);
			if (list3 == null || list3.Count < 1)
			{
				return false;
			}
			List<RadiatorConnParam> list4 = this.OrderByRadiatorSingle(list3, ref basePnt);
			if (list4 == null || list4.Count < 1)
			{
				result = false;
				return result;
			}
			if (this.ConnStyle == 1)
			{
				result = this.ConnDoublePipes(list4, basePnt);
			}
			if (this.ConnStyle == 2)
			{
				result = this.ConnDownPipes(list4, basePnt);
			}
			if (this.ConnStyle == 3)
			{
				result = this.ConnCrossPipes(list4, basePnt);
			}
			int num = list.Count - list2.Count;
			if (num > 0)
			{
				YJKMessageBox.Information("选择连接的散热器中有" + num + "个散热器族，\n由于族的问题找不到相应的连接口，\n不能进行连接，请检查！");
			}
			return result;
		}

		public XYZ GetBasePoint()
		{
			XYZ result = null;
			if (this.SupplyPipe == null)
			{
				return result;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(this.SupplyPipe);
			XYZ origin = hypiping.StartConnector.Connector.Origin;
			XYZ origin2 = hypiping.EndConnector.Connector.Origin;
			XYZ loctaionPoint = YJKRevitTools.GetLoctaionPoint(this.ListRadiator[0]);
			return (origin.DistanceTo(loctaionPoint) > origin2.DistanceTo(loctaionPoint)) ? origin2 : origin;
		}

		private bool CheckPipeEquipmentRelation(Connector conn, Pipe pipe)
		{
			XYZ origin = conn.Origin;
			XYZ end = origin.Add(conn.CoordinateSystem.BasisZ);
			YJKLine hyline = new YJKLine(origin, end);
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			YJKLine hyline2 = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			return hyline2.IsParallel(hyline.Line) || hyline2.IsVertical(hyline.Line);
		}

		private bool ConnDoublePipes(List<RadiatorConnParam> radiatorSet, XYZ basePnt)
		{
			bool result = true;
			try
			{
				Pipe farPipeToPoint = this.SupplyPipe;
				Pipe farPipeToPoint2 = this.ReturnPipe;
				foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
				{
					if (!this.CheckPipeEquipmentRelation(radiatorConnParam.InConnector, farPipeToPoint) && !this.CheckPipeEquipmentRelation(radiatorConnParam.InConnector, farPipeToPoint2))
					{
						throw new Exception("散热器连接口应与连接管道平行或垂直！");
					}
					basePnt.DistanceTo(radiatorConnParam.PntOnPipeIn);
					basePnt.DistanceTo(radiatorConnParam.PntOnPipeOut);
					IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 2);
					this.Doc.Regenerate();
					farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
					IList<Pipe> list2 = this.ConnPipe(radiatorConnParam, farPipeToPoint2, 1);
					this.Doc.Regenerate();
					farPipeToPoint2 = this.GetFarPipeToPoint(list2, basePnt);
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnCrossPipes(List<RadiatorConnParam> radiatorSet, XYZ basePnt)
		{
			bool result = true;
			try
			{
				Pipe farPipeToPoint = this.SupplyPipe;
				foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
				{
					if (!this.CheckPipeEquipmentRelation(radiatorConnParam.InConnector, farPipeToPoint))
					{
						throw new Exception("散热器连接口应与连接管道平行或垂直！");
					}
					double num = basePnt.DistanceTo(radiatorConnParam.PntOnPipeIn);
					double num2 = basePnt.DistanceTo(radiatorConnParam.PntOnPipeOut);
					if (num <= num2)
					{
						IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 2);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 1);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
					}
					else
					{
						IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 1);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						list = this.ConnPipe(radiatorConnParam, farPipeToPoint, 2);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
					}
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnDownPipes(List<RadiatorConnParam> radiatorSet, XYZ basePnt)
		{
			bool result = true;
			try
			{
				Pipe farPipeToPoint = this.SupplyPipe;
				foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
				{
					if (!this.CheckPipeEquipmentRelation(radiatorConnParam.InConnector, farPipeToPoint))
					{
						throw new Exception("散热器连接口应与连接管道平行或垂直！");
					}
					double num = basePnt.DistanceTo(radiatorConnParam.PntOnPipeIn);
					double num2 = basePnt.DistanceTo(radiatorConnParam.PntOnPipeOut);
					if (num <= num2)
					{
						IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, basePnt, 1, 2);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						list = this.ConnPipe(radiatorConnParam, farPipeToPoint, basePnt, 2, 1);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						if (list.Count > 1)
						{
							this.Doc.DeleteElement(this.GetPipeToPoint(list, basePnt, 2));
						}
						this.Doc.Regenerate();
					}
					else
					{
						IList<Pipe> list = this.ConnPipe(radiatorConnParam, farPipeToPoint, basePnt, 2, 2);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						list = this.ConnPipe(radiatorConnParam, farPipeToPoint, basePnt, 1, 1);
						this.Doc.Regenerate();
						farPipeToPoint = this.GetFarPipeToPoint(list, basePnt);
						if (list.Count > 1)
						{
							this.Doc.DeleteElement(this.GetPipeToPoint(list, basePnt, 2));
						}
						this.Doc.Regenerate();
					}
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnDownPipes(RadiatorConnParam radiator)
		{
			bool result = true;
			try
			{
				bool beUp = true;
				bool beUp2 = true;
				this.JudgeConnPosition(radiator.ElementId, ref beUp, ref beUp2);
				Pipe pipeByOffset = this.SupplyPipe;
				double z = radiator.InConnector.Origin.Z;
				double z2 = radiator.OutConnector.Origin.Z;
				if (z <= z2)
				{
					IList<Pipe> list = this.ConnRiserPipes(radiator.OutPipe, pipeByOffset, 1, ref this.message, beUp);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 2);
					if (pipeByOffset == null)
					{
						pipeByOffset = this.SupplyPipe;
					}
					list = this.ConnRiserPipes(radiator.InPipe, pipeByOffset, 2, ref this.message, beUp2);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 1);
					if (list.Count > 1)
					{
						this.Doc.DeleteElement(pipeByOffset);
					}
					this.Doc.Regenerate();
				}
				else
				{
					IList<Pipe> list = this.ConnRiserPipes(radiator.InPipe, pipeByOffset, 1, ref this.message, beUp);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 2);
					if (pipeByOffset == null)
					{
						pipeByOffset = this.SupplyPipe;
					}
					list = this.ConnRiserPipes(radiator.OutPipe, pipeByOffset, 2, ref this.message, beUp2);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 1);
					if (list.Count > 1)
					{
						this.Doc.DeleteElement(pipeByOffset);
					}
					this.Doc.Regenerate();
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnCrossPipes(RadiatorConnParam radiator)
		{
			bool result = true;
			try
			{
				bool beUp = true;
				bool beUp2 = true;
				this.JudgeConnPosition(radiator.ElementId, ref beUp, ref beUp2);
				Pipe pipeByOffset = this.SupplyPipe;
				double z = radiator.InConnector.Origin.Z;
				double z2 = radiator.OutConnector.Origin.Z;
				if (z <= z2)
				{
					IList<Pipe> list = this.ConnRiserPipes(radiator.OutPipe, pipeByOffset, ref this.message, beUp);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 2);
					if (pipeByOffset == null)
					{
						pipeByOffset = this.SupplyPipe;
					}
					list = this.ConnRiserPipes(radiator.InPipe, pipeByOffset, ref this.message, beUp2);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 1);
					this.Doc.Regenerate();
				}
				else
				{
					IList<Pipe> list = this.ConnRiserPipes(radiator.InPipe, pipeByOffset, ref this.message, beUp);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 2);
					if (pipeByOffset == null)
					{
						pipeByOffset = this.SupplyPipe;
					}
					list = this.ConnRiserPipes(radiator.OutPipe, pipeByOffset, ref this.message, beUp2);
					this.Doc.Regenerate();
					pipeByOffset = this.GetPipeByOffset(list, 1);
					this.Doc.Regenerate();
				}
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private bool ConnDoublePipes(RadiatorConnParam radiator)
		{
			bool result = true;
			try
			{
				bool beUp = true;
				bool beUp2 = true;
				this.JudgeConnPosition(radiator.ElementId, ref beUp, ref beUp2);
				Pipe mainPipe = this.SupplyPipe;
				Pipe mainPipe2 = this.ReturnPipe;
				this.ConnRiserPipes(radiator.OutPipe, mainPipe2, ref this.message, beUp2);
				this.Doc.Regenerate();
				this.ConnRiserPipes(radiator.InPipe, mainPipe, ref this.message, beUp);
				this.Doc.Regenerate();
			}
			catch (Exception ex)
			{
				result = false;
				this.Message = ex.Message;
			}
			return result;
		}

		private IList<Pipe> ConnPipe(RadiatorConnParam radiatorConn, Pipe pipe, XYZ basePnt, int styleNum, int connNum)
		{
			IList<Pipe> list = new List<Pipe>();
			if (pipe == null)
			{
				return list;
			}
			Pipe pipe2;
			if (styleNum == 1)
			{
				pipe2 = radiatorConn.InPipe;
			}
			else
			{
				pipe2 = radiatorConn.OutPipe;
			}
			if (radiatorConn.ReDirection == 0)
			{
				list = this.ConnectParallelPipes(pipe2, pipe, basePnt, connNum, ref this.message);
			}
			else
			{
				list = this.ConnInterSectionPipes(pipe2, pipe, basePnt, connNum, ref this.message);
			}
			if (list == null || list.Count < 1)
			{
				list = new List<Pipe>();
				list.Add(pipe);
			}
			return list;
		}

		private IList<Pipe> ConnPipe(RadiatorConnParam radiatorConn, Pipe pipe, int styleNum)
		{
			IList<Pipe> result = new List<Pipe>();
			if (pipe == null)
			{
				return result;
			}
			Pipe pipe2;
			if (styleNum == 2)
			{
				pipe2 = radiatorConn.InPipe;
			}
			else
			{
				pipe2 = radiatorConn.OutPipe;
			}
			if (radiatorConn.ReDirection == 0)
			{
				result = this.ConnectParallelPipes(pipe2, pipe, ref this.message);
			}
			else
			{
				result = this.ConnInterSectionPipes(pipe2, pipe, ref this.message);
			}
			return result;
		}

		private List<Pipe> ConnectParallelPipes(Pipe sidePipe, Pipe mainPipe, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			List<Pipe> result = new List<Pipe>();
			Document document = mainPipe.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(project.X, project.Y, xyz.Z);
			double num = project.DistanceTo(xyz2);
			double num2 = xyz2.DistanceTo(xyz);
			double num3 = 0.016404199475065617;
			double num4 = (diameter + diameter2) * 2.0;
			if (num <= num3)
			{
				if (num2 < num4)
				{
					connMSG = "两管间距不合适，不能进行连接";
					return result;
				}
				Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe, diameter);
				this.ConnPipeByEblow(pipe, hypiping.Piping);
				result = this.ConnectMainPipe(hyline, hypiping2, project, pipe);
			}
			else if (num >= num4)
			{
				if (num2 <= num3)
				{
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, hypiping.Piping);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2);
				}
				else
				{
					if (num2 < num4)
					{
						connMSG = "两管间距不合适，不能进行连接";
						return result;
					}
					Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
					this.SetDiameter(pipe, diameter);
					this.ConnPipeByEblow(pipe, hypiping.Piping);
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, pipe);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return result;
		}

		private List<Pipe> ConnectMainPipe(YJKLine lineMain, YJKPiping<Pipe> hyMain, XYZ proPoint, Pipe tranPipe)
		{
			List<Pipe> list = new List<Pipe>();
			double diameter = hyMain.GetDiameter();
			if (lineMain.IsPointOnLine(proPoint) && lineMain.StartPoint.DistanceTo(proPoint) >= diameter * 1.5 && lineMain.EndPoint.DistanceTo(proPoint) >= diameter * 1.5)
			{
				this.listPipe = hyMain.Separate(proPoint);
				hyMain.Piping.Document.Regenerate();
				this.ConnPipeByTee(this.listPipe[0], this.listPipe[1], tranPipe);
				list.Add(this.listPipe[0]);
				list.Add(this.listPipe[1]);
			}
			else
			{
				this.ConnPipeByEblow(tranPipe, hyMain.Piping);
				list.Add(hyMain.Piping);
			}
			return list;
		}

		private void ConnPipeByEblow(Pipe pipe1, Pipe pipe2)
		{
			IList<Pipe> list = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			hyrotateFamilyInstance.MovePiping(pipe1);
			hyrotateFamilyInstance.MovePiping(pipe2);
			list.Add(pipe1);
			list.Add(pipe2);
			hypipeConnect.NewElbowFitting(list, true);
		}

		private void ConnPipeByTee(Pipe pipe1, Pipe pipe2, Pipe pipe3)
		{
			IList<Pipe> list = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			hyrotateFamilyInstance.MovePiping(pipe1);
			hyrotateFamilyInstance.MovePiping(pipe2);
			hyrotateFamilyInstance.MovePiping(pipe3);
			list.Add(pipe1);
			list.Add(pipe2);
			list.Add(pipe3);
			hypipeConnect.NewTeeFitting(ref list, true);
		}

		private List<Pipe> ConnParallelPipes(Pipe sidePipe, Pipe mainPipe, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			List<Pipe> list = new List<Pipe>();
			Pipe piping = hypiping2.Piping;
			Document document = hypiping.Piping.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(project.X, project.Y, xyz.Z);
			double num = project.DistanceTo(xyz2);
			IList<Pipe> list2 = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (num <= 0.016404199475065617)
			{
				Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe, diameter);
				list2.Add(pipe);
				list2.Add(hypiping.Piping);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list3[0]);
					list2.Add(list3[1]);
					list2.Add(pipe);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping2.Piping);
					list2.Add(pipe);
					hypipeConnect.NewElbowFitting(list2, true);
					list.Add(hypiping2.Piping);
				}
			}
			else if (num >= (diameter + diameter2) * 1.5)
			{
				Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
				this.SetDiameter(pipe2, diameter);
				list2.Add(pipe2);
				list2.Add(hypiping.Piping);
				hypipeConnect.NewElbowFitting(list2, true);
				Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
				this.SetDiameter(pipe3, diameter);
				list2 = new List<Pipe>();
				list2.Add(pipe2);
				list2.Add(pipe3);
				hyrotateFamilyInstance.MovePiping(pipe3);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe3);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list3[0]);
					list2.Add(list3[1]);
					list2.Add(pipe3);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping2.Piping);
					list2.Add(pipe3);
					hypipeConnect.NewElbowFitting(list2, true);
					list.Add(hypiping2.Piping);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnectParallelPipes(Pipe sidePipe, Pipe mainPipe, XYZ basePnt, int styleNum, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			List<Pipe> result = new List<Pipe>();
			Document document = mainPipe.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(project.X, project.Y, xyz.Z);
			double num = project.DistanceTo(xyz2);
			double num2 = xyz2.DistanceTo(xyz);
			double num3 = 0.016404199475065617;
			double num4 = (diameter + diameter2) * 2.0;
			if (num <= num3)
			{
				if (num2 < num4)
				{
					connMSG = "两管间距不合适，不能进行连接";
					return result;
				}
				Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe, diameter);
				this.ConnPipeByEblow(pipe, hypiping.Piping);
				result = this.ConnectMainPipe(hyline, hypiping2, project, pipe, basePnt, styleNum);
			}
			else if (num >= num4)
			{
				if (num2 <= num3)
				{
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, hypiping.Piping);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2, basePnt, styleNum);
				}
				else
				{
					if (num2 < num4)
					{
						connMSG = "两管间距不合适，不能进行连接";
						return result;
					}
					Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
					this.SetDiameter(pipe, diameter);
					this.ConnPipeByEblow(pipe, hypiping.Piping);
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
					this.SetDiameter(pipe2, diameter);
					this.ConnPipeByEblow(pipe2, pipe);
					result = this.ConnectMainPipe(hyline, hypiping2, project, pipe2, basePnt, styleNum);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return result;
		}

		private List<Pipe> ConnectMainPipe(YJKLine lineMain, YJKPiping<Pipe> hyMain, XYZ proPoint, Pipe tranPipe, XYZ basePnt, int styleNum)
		{
			List<Pipe> list = new List<Pipe>();
			double diameter = hyMain.GetDiameter();
			if (lineMain.IsPointOnLine(proPoint) && lineMain.StartPoint.DistanceTo(proPoint) >= diameter * 1.5 && lineMain.EndPoint.DistanceTo(proPoint) >= diameter * 1.5)
			{
				this.listPipe = hyMain.Separate(proPoint);
				hyMain.Piping.Document.Regenerate();
				Pipe pipeToPoint = this.GetPipeToPoint(this.listPipe, basePnt, styleNum);
				this.ConnPipeByEblow(pipeToPoint, tranPipe);
				list.Add(this.listPipe[0]);
				list.Add(this.listPipe[1]);
			}
			return list;
		}

		private List<Pipe> ConnParallelPipes(Pipe sidePipe, Pipe mainPipe, XYZ basePnt, int styleNum, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(sidePipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(mainPipe);
			List<Pipe> list = new List<Pipe>();
			Pipe piping = hypiping2.Piping;
			Document document = hypiping.Piping.Document;
			XYZ xyz = hypiping.StartConnector.Connector.IsConnected ? hypiping.EndConnector.Origin : hypiping.StartConnector.Origin;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline.MakeUnBound();
			XYZ project = hyline.GetProject(xyz);
			XYZ xyz2 = new XYZ(project.X, project.Y, xyz.Z);
			double num = project.DistanceTo(xyz2);
			IList<Pipe> list2 = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (num <= 0.016404199475065617)
			{
				Pipe pipe = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe, diameter);
				list2.Add(pipe);
				list2.Add(hypiping.Piping);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeToPoint(list3, basePnt, styleNum),
						pipe
					}, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
			}
			else if (num >= (diameter + diameter2) * 1.5)
			{
				Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, xyz2);
				this.SetDiameter(pipe2, diameter);
				list2.Add(pipe2);
				list2.Add(hypiping.Piping);
				hypipeConnect.NewElbowFitting(list2, true);
				Pipe pipe3 = YJKRevitTools.NewPipe(hypiping.Piping, xyz2, project);
				this.SetDiameter(pipe3, diameter);
				list2 = new List<Pipe>();
				list2.Add(pipe2);
				list2.Add(pipe3);
				hyrotateFamilyInstance.MovePiping(pipe3);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe3);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeToPoint(list3, basePnt, styleNum),
						pipe3
					}, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnInterSectionPipes(Pipe side, Pipe main, XYZ basePnt, int styleNum, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(side);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(main);
			List<Pipe> list = new List<Pipe>();
			Document document = side.Document;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			XYZ closePipePoint = this.GetClosePipePoint(hypiping, hypiping2);
			XYZ project = hyline.GetProject(closePipePoint);
			XYZ xyz = new XYZ(project.X, project.Y, closePipePoint.Z);
			double num = project.DistanceTo(xyz);
			IList<Pipe> list2 = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (num <= 0.016404199475065617)
			{
				Pipe pipe = hypiping.Piping;
				if (!hyline2.IsPointOnCurveLine(project))
				{
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, closePipePoint, project);
					this.SetDiameter(pipe, diameter);
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						pipe,
						pipe2
					}, true);
					pipe = pipe2;
				}
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeToPoint(list3, basePnt, styleNum),
						pipe
					}, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
			}
			else if (num > (diameter + diameter2) * 1.5)
			{
				Pipe pipe3 = hypiping.Piping;
				if (!hyline2.IsPointOnCurveLine(xyz))
				{
					Pipe pipe4 = YJKRevitTools.NewPipe(hypiping.Piping, closePipePoint, xyz);
					this.SetDiameter(pipe3, diameter);
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						pipe3,
						pipe4
					}, true);
					pipe3 = pipe4;
				}
				Pipe pipe5 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe5, diameter);
				hyrotateFamilyInstance.MovePiping(pipe5);
				hypipeConnect.NewElbowFitting(new List<Pipe>
				{
					pipe3,
					pipe5
				}, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe5);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						pipe5,
						this.GetPipeToPoint(list3, basePnt, styleNum)
					}, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnInterSectionPipes(Pipe side, Pipe main, ref string connMSG)
		{
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(side);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(main);
			List<Pipe> list = new List<Pipe>();
			Document document = side.Document;
			double diameter = hypiping.GetDiameter();
			double diameter2 = hypiping2.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			XYZ closePipePoint = this.GetClosePipePoint(hypiping, hypiping2);
			XYZ project = hyline.GetProject(closePipePoint);
			XYZ xyz = new XYZ(project.X, project.Y, closePipePoint.Z);
			double num = project.DistanceTo(xyz);
			IList<Pipe> list2 = new List<Pipe>();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (num <= 0.016404199475065617)
			{
				Pipe pipe = hypiping.Piping;
				if (!hyline2.IsPointOnCurveLine(project))
				{
					Pipe pipe2 = YJKRevitTools.NewPipe(hypiping.Piping, closePipePoint, project);
					this.SetDiameter(pipe, diameter);
					list2 = new List<Pipe>();
					list2.Add(pipe);
					list2.Add(pipe2);
					hypipeConnect.NewElbowFitting(list2, true);
					pipe = pipe2;
				}
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list3[0]);
					list2.Add(list3[1]);
					list2.Add(pipe);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping2.Piping);
					list2.Add(pipe);
					hypipeConnect.NewElbowFitting(list2, true);
					list.Add(hypiping2.Piping);
				}
			}
			else if (num > (diameter + diameter2) * 1.5)
			{
				Pipe pipe3 = hypiping.Piping;
				if (!hyline2.IsPointOnCurveLine(xyz))
				{
					Pipe pipe4 = YJKRevitTools.NewPipe(hypiping.Piping, closePipePoint, xyz);
					this.SetDiameter(pipe3, diameter);
					list2 = new List<Pipe>();
					list2.Add(pipe3);
					list2.Add(pipe4);
					hypipeConnect.NewElbowFitting(list2, true);
					pipe3 = pipe4;
				}
				Pipe pipe5 = YJKRevitTools.NewPipe(hypiping.Piping, xyz, project);
				this.SetDiameter(pipe5, diameter);
				hyrotateFamilyInstance.MovePiping(pipe5);
				list2 = new List<Pipe>();
				list2.Add(pipe3);
				list2.Add(pipe5);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					List<Pipe> list3 = hypiping2.Separate(project);
					hyrotateFamilyInstance.MovePiping(list3[0]);
					hyrotateFamilyInstance.MovePiping(list3[1]);
					hyrotateFamilyInstance.MovePiping(pipe5);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list3[0]);
					list2.Add(list3[1]);
					list2.Add(pipe5);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list.Add(list3[0]);
					list.Add(list3[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping2.Piping);
					list2.Add(pipe5);
					hypipeConnect.NewElbowFitting(list2, true);
					list.Add(hypiping2.Piping);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private void ConnectPipeByElbow(HYPipeConnect hyConnPipe, Pipe pipe1, Pipe pipe2)
		{
			hyConnPipe.NewElbowFitting(new List<Pipe>
			{
				pipe1,
				pipe2
			}, true);
			this.doc.Regenerate();
		}

		private Pipe CreatTranPipe(Pipe basePipe, XYZ startPne, XYZ pipeVector, double pipeLength)
		{
			XYZ endXYZ = startPne.Add(pipeLength * pipeVector);
			Pipe pipe = YJKRevitTools.NewPipe(basePipe, startPne, endXYZ);
			this.doc.Regenerate();
			new YJKRotateFamilyInstance().MovePiping(pipe);
			return pipe;
		}

		private List<Pipe> ConnRiserPipes(Pipe sidePipe, Pipe mainPipe, ref string connMSG, bool beUp = true)
		{
			List<Pipe> list = new List<Pipe>();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(sidePipe);
			Document document = mainPipe.Document;
			double diameter = hypiping2.GetDiameter();
			double diameter2 = hypiping.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline2.MakeUnBound();
			Connector notConnector = this.GetNotConnector(sidePipe);
			XYZ project = hyline.GetProject(notConnector.Origin);
			XYZ project2 = hyline2.GetProject(project);
			XYZ xyz = project2.Subtract(notConnector.Origin).Normalize();
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			IList<Pipe> list2 = new List<Pipe>();
			if (!xyz.IsAlmostEqualTo(notConnector.CoordinateSystem.BasisZ))
			{
				connMSG = "连接口方向与连接管道相反，是否继续连接";
				if (YJKMessageBox.Show(connMSG, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
				{
					return list;
				}
				XYZ xyz2 = new XYZ(0.0, 0.0, 1.0);
				if (!beUp)
				{
					xyz2 = -1.0 * xyz2;
				}
				double num = hypiping2.GetDiameter() * 12.0;
				XYZ xyz3 = notConnector.Origin.Add(num * xyz2);
				Pipe pipe = this.CreatTranPipe(hypiping2.Piping, notConnector.Origin, xyz2, num);
				this.ConnectPipeByElbow(hypipeConnect, hypiping2.Piping, pipe);
				XYZ xyz4 = notConnector.CoordinateSystem.BasisZ * -1.0;
				Pipe pipe2 = this.CreatTranPipe(hypiping2.Piping, xyz3, xyz4, num);
				this.ConnectPipeByElbow(hypipeConnect, pipe2, pipe);
				hypiping2 = new YJKPiping<Pipe>(pipe2);
				project = hyline.GetProject(xyz3);
				YJKLine hyline3 = new YJKLine(xyz3, xyz3.Add(xyz4 * 2.0));
				hyline3.MakeUnBound();
				project2 = hyline3.GetProject(project);
			}
			double num2 = project2.DistanceTo(project);
			List<Pipe> list3 = new List<Pipe>();
			if (num2 <= 0.016404199475065617)
			{
				Pipe piping = hypiping2.Piping;
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(piping);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(piping);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(piping);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
			}
			else if (num2 > (diameter + diameter2) * 1.5)
			{
				Pipe piping2 = hypiping2.Piping;
				Pipe pipe3 = YJKRevitTools.NewPipe(hypiping2.Piping, project2, project);
				this.SetDiameter(pipe3, diameter);
				hyrotateFamilyInstance.MovePiping(pipe3);
				list2 = new List<Pipe>();
				list2.Add(piping2);
				list2.Add(pipe3);
				hypipeConnect.NewElbowFitting(list2, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe3);
					document.Regenerate();
					list2 = new List<Pipe>();
					list2.Add(list[0]);
					list2.Add(list[1]);
					list2.Add(pipe3);
					hypipeConnect.NewTeeFitting(ref list2, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
				else
				{
					list2 = new List<Pipe>();
					list2.Add(hypiping.Piping);
					list2.Add(pipe3);
					hypipeConnect.NewElbowFitting(list2, true);
					list3.Add(hypiping.Piping);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private List<Pipe> ConnRiserPipes(Pipe sidePipe, Pipe mainPipe, int styleNum, ref string connMSG, bool beUp)
		{
			List<Pipe> list = new List<Pipe>();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(mainPipe);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(sidePipe);
			Document document = mainPipe.Document;
			double diameter = hypiping2.GetDiameter();
			double diameter2 = hypiping.GetDiameter();
			YJKLine hyline = new YJKLine(hypiping.StartConnector.Origin, hypiping.EndConnector.Origin);
			hyline.MakeUnBound();
			YJKLine hyline2 = new YJKLine(hypiping2.StartConnector.Origin, hypiping2.EndConnector.Origin);
			hyline2.MakeUnBound();
			Connector notConnector = this.GetNotConnector(sidePipe);
			XYZ project = hyline.GetProject(notConnector.Origin);
			XYZ project2 = hyline2.GetProject(project);
			XYZ xyz = project2.Subtract(notConnector.Origin).Normalize();
			HYPipeConnect hypipeConnect = new HYPipeConnect();
			if (!xyz.IsAlmostEqualTo(notConnector.CoordinateSystem.BasisZ))
			{
				connMSG = "连接口方向与连接管道相反，是否继续连接";
				if (YJKMessageBox.Show(connMSG, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
				{
					return list;
				}
				XYZ xyz2 = new XYZ(0.0, 0.0, 1.0);
				if (!beUp)
				{
					xyz2 = -1.0 * xyz2;
				}
				double num = hypiping2.GetDiameter() * 12.0;
				XYZ xyz3 = notConnector.Origin.Add(num * xyz2);
				Pipe pipe = this.CreatTranPipe(hypiping2.Piping, notConnector.Origin, xyz2, num);
				this.ConnectPipeByElbow(hypipeConnect, hypiping2.Piping, pipe);
				XYZ xyz4 = notConnector.CoordinateSystem.BasisZ * -1.0;
				Pipe pipe2 = this.CreatTranPipe(hypiping2.Piping, xyz3, xyz4, num);
				this.ConnectPipeByElbow(hypipeConnect, pipe2, pipe);
				hypiping2 = new YJKPiping<Pipe>(pipe2);
				project = hyline.GetProject(xyz3);
				YJKLine hyline3 = new YJKLine(xyz3, xyz3.Add(xyz4 * 2.0));
				hyline3.MakeUnBound();
				project2 = hyline3.GetProject(project);
			}
			double num2 = project2.DistanceTo(project);
			YJKRotateFamilyInstance hyrotateFamilyInstance = new YJKRotateFamilyInstance();
			IList<Pipe> list2 = new List<Pipe>();
			List<Pipe> list3 = new List<Pipe>();
			if (num2 <= 0.016404199475065617)
			{
				Pipe piping = hypiping2.Piping;
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(piping);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeByOffset(list, styleNum),
						piping
					}, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
			}
			else if (num2 > (diameter + diameter2) * 1.5)
			{
				Pipe piping2 = hypiping2.Piping;
				Pipe pipe3 = YJKRevitTools.NewPipe(hypiping2.Piping, project2, project);
				this.SetDiameter(pipe3, diameter);
				hyrotateFamilyInstance.MovePiping(pipe3);
				hypipeConnect.NewElbowFitting(new List<Pipe>
				{
					piping2,
					pipe3
				}, true);
				if (hyline.IsPointOnLine(project) && hyline.StartPoint.DistanceTo(project) >= diameter2 * 1.5 && hyline.EndPoint.DistanceTo(project) >= diameter2 * 1.5)
				{
					list = hypiping.Separate(project);
					hyrotateFamilyInstance.MovePiping(list[0]);
					hyrotateFamilyInstance.MovePiping(list[1]);
					hyrotateFamilyInstance.MovePiping(pipe3);
					document.Regenerate();
					hypipeConnect.NewElbowFitting(new List<Pipe>
					{
						this.GetPipeByOffset(list, styleNum),
						pipe3
					}, true);
					list3.Add(list[0]);
					list3.Add(list[1]);
				}
			}
			else
			{
				connMSG = "两管间距不合适，不能进行连接";
			}
			return list;
		}

		private Connector GetNotConnector(Pipe pipe)
		{
			Connector result = null;
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			if (!hypiping.StartConnector.Connector.IsConnected)
			{
				result = hypiping.StartConnector.Connector;
			}
			if (!hypiping.EndConnector.Connector.IsConnected)
			{
				result = hypiping.EndConnector.Connector;
			}
			return result;
		}

		private Pipe GetFarPipeToPoint(IList<Pipe> listPipe, XYZ point)
		{
			Pipe result = null;
			double num = 0.0;
			foreach (Pipe pipe in listPipe)
			{
				YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
				XYZ xyz = hypiping.StartConnector.Origin.Add(hypiping.EndConnector.Origin) / 2.0;
				if (xyz.DistanceTo(point) > num)
				{
					num = xyz.DistanceTo(point);
					result = pipe;
				}
			}
			return result;
		}

		private Pipe GetPipeByOffset(IList<Pipe> listPipe, int styleNum)
		{
			Pipe result = null;
			if (listPipe.Count != 2)
			{
				return result;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(listPipe[0]);
			YJKPiping<Pipe> hypiping2 = new YJKPiping<Pipe>(listPipe[1]);
			XYZ xyz = hypiping.StartConnector.Origin.Add(hypiping.EndConnector.Origin) / 2.0;
			XYZ xyz2 = hypiping2.StartConnector.Origin.Add(hypiping2.EndConnector.Origin) / 2.0;
			if (styleNum == 1)
			{
				if (xyz.Z > xyz2.Z)
				{
					result = listPipe[0];
				}
				else
				{
					result = listPipe[1];
				}
			}
			if (styleNum == 2)
			{
				if (xyz.Z > xyz2.Z)
				{
					result = listPipe[1];
				}
				else
				{
					result = listPipe[0];
				}
			}
			return result;
		}

		private Pipe GetPipeToPoint(IList<Pipe> listPipe, XYZ point, int styleNum)
		{
			Pipe result = null;
			double num = 0.0;
			for (int i = 0; i < listPipe.Count; i++)
			{
				YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(listPipe[i]);
				XYZ xyz = hypiping.StartConnector.Origin.Add(hypiping.EndConnector.Origin) / 2.0;
				if (i == 0)
				{
					num = xyz.DistanceTo(point);
				}
				if (styleNum == 1 && xyz.DistanceTo(point) >= num)
				{
					num = xyz.DistanceTo(point);
					result = listPipe[i];
				}
				if (styleNum == 2 && xyz.DistanceTo(point) <= num)
				{
					num = xyz.DistanceTo(point);
					result = listPipe[i];
				}
			}
			return result;
		}

		private XYZ GetClosePipePoint(YJKPiping<Pipe> hySide, YJKPiping<Pipe> hyMain)
		{
			YJKLine hyline = new YJKLine(hySide.StartConnector.Origin, hySide.EndConnector.Origin);
			YJKLine hyline2 = new YJKLine(hyMain.StartConnector.Origin, hyMain.EndConnector.Origin);
			hyline2.MakeUnBound();
			if (hyline2.GetDistance(hyline.EndPoint) <= hyline2.GetDistance(hyline.StartPoint))
			{
				return hyline.EndPoint;
			}
			return hyline.StartPoint;
		}

		private List<RadiatorConnParam> OrderByRadiatorSingle(List<RadiatorConnParam> radiatorSet, ref XYZ basePnt)
		{
			List<RadiatorConnParam> list = new List<RadiatorConnParam>();
			if (!this.ChangePipeLine(ref radiatorSet, 1, ref basePnt))
			{
				YJKMessageBox.Warning("连接用管道不能为空。");
				return list;
			}
			this.Doc.Regenerate();
			if (!this.ChangePipeLine(ref radiatorSet, 2, ref basePnt))
			{
				YJKMessageBox.Warning("连接用管道不能为空。");
				return list;
			}
			this.Doc.Regenerate();
			if (this.SupplyPipe == null)
			{
				YJKMessageBox.Warning("连接用管道不能为空。");
				return list;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(this.SupplyPipe);
			XYZ origin = hypiping.StartConnector.Origin;
			XYZ origin2 = hypiping.EndConnector.Origin;
			XYZ xyz = origin.Subtract(origin2).Normalize();
			basePnt = ((origin.DistanceTo(basePnt) > origin2.DistanceTo(basePnt)) ? origin2 : origin);
			double num = 0.0001;
			foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
			{
				double distanceOfEnd = radiatorConnParam.InExPipeConn.Origin.DistanceTo(basePnt);
				radiatorConnParam.DistanceOfEnd = distanceOfEnd;
				XYZ basisZ = radiatorConnParam.InConnector.CoordinateSystem.BasisZ;
				XYZ direction = xyz.CrossProduct(basisZ);
				double twoVectorAngle = YJKRevitTools.GetTwoVectorAngle(xyz, basisZ, direction);
				if (twoVectorAngle <= num || Math.Abs(twoVectorAngle - Math.PI) <= num || Math.Abs(twoVectorAngle - Math.PI*2) < num)
				{
					radiatorConnParam.ReDirection = 0;
				}
				else if (Math.Abs(twoVectorAngle - Math.PI*.5) <= num || Math.Abs(twoVectorAngle - 4.71238898038469) <= num)
				{
					radiatorConnParam.ReDirection = 1;
				}
				else
				{
					radiatorConnParam.ReDirection = 2;
				}
			}
			list = (from c in radiatorSet
			orderby c.DistanceOfEnd
			select c).ToList<RadiatorConnParam>();
			int num2 = 1;
			for (int i = 0; i < list.Count; i++)
			{
				if (i == 0)
				{
					list[i].IndexOfPipe = num2;
				}
				else if (Math.Abs(list[i].DistanceOfEnd - list[i - 1].DistanceOfEnd) < 0.032808398950131233)
				{
					list[i].IndexOfPipe = num2;
				}
				else
				{
					num2++;
					list[i].IndexOfPipe = num2;
				}
			}
			return list;
		}

		private List<RadiatorConnParam> OrderByRadiatorDouble(List<RadiatorConnParam> radiatorSet, ref XYZ basePnt)
		{
			List<RadiatorConnParam> list = new List<RadiatorConnParam>();
			this.ChangePipeLine(ref radiatorSet, 1, ref basePnt);
			this.ChangePipeLine(ref radiatorSet, 2, ref basePnt);
			if (this.SupplyPipe == null)
			{
				return list;
			}
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(this.SupplyPipe);
			XYZ origin = hypiping.StartConnector.Origin;
			XYZ origin2 = hypiping.EndConnector.Origin;
			XYZ xyz = origin.Subtract(origin2).Normalize();
			basePnt = ((origin.DistanceTo(basePnt) > origin2.DistanceTo(basePnt)) ? origin2 : origin);
			double num = 0.0001;
			foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
			{
				double distanceOfEnd = radiatorConnParam.InExPipeConn.Origin.DistanceTo(basePnt);
				radiatorConnParam.DistanceOfEnd = distanceOfEnd;
				XYZ basisZ = radiatorConnParam.InConnector.CoordinateSystem.BasisZ;
				XYZ direction = xyz.CrossProduct(basisZ);
				double twoVectorAngle = YJKRevitTools.GetTwoVectorAngle(xyz, basisZ, direction);
				if (twoVectorAngle <= num || Math.Abs(twoVectorAngle - Math.PI) <= num || Math.Abs(twoVectorAngle - Math.PI*2) < num)
				{
					radiatorConnParam.ReDirection = 0;
				}
				else if (Math.Abs(twoVectorAngle - Math.PI*.5) <= num || Math.Abs(twoVectorAngle - 4.71238898038469) <= num)
				{
					radiatorConnParam.ReDirection = 1;
				}
				else
				{
					radiatorConnParam.ReDirection = 2;
				}
			}
			list = (from c in radiatorSet
			orderby c.DistanceOfEnd
			select c).ToList<RadiatorConnParam>();
			int num2 = 1;
			for (int i = 0; i < list.Count; i++)
			{
				if (i == 0)
				{
					list[i].IndexOfPipe = num2;
				}
				else if (Math.Abs(list[i].DistanceOfEnd - list[i - 1].DistanceOfEnd) < 0.032808398950131233)
				{
					list[i].IndexOfPipe = num2;
				}
				else
				{
					num2++;
					list[i].IndexOfPipe = num2;
				}
			}
			return list;
		}

		private bool ChangePipeLine(ref List<RadiatorConnParam> radiatorSet, int style, ref XYZ basePnt)
		{
			YJKPiping<Pipe> hypiping = null;
			if (style == 2 && this.ConnStyle == 1)
			{
				if (this.ReturnPipe != null)
				{
					hypiping = new YJKPiping<Pipe>(this.ReturnPipe);
				}
			}
			else if (this.SupplyPipe != null)
			{
				hypiping = new YJKPiping<Pipe>(this.SupplyPipe);
			}
			if (hypiping == null)
			{
				return false;
			}
			XYZ origin = hypiping.StartConnector.Origin;
			XYZ origin2 = hypiping.EndConnector.Origin;
			XYZ xyz = null;
			if (origin.DistanceTo(basePnt) < origin2.DistanceTo(basePnt))
			{
				basePnt = origin;
				xyz = origin2;
			}
			else
			{
				basePnt = origin2;
				xyz = origin;
			}
			YJKLine hyline = new YJKLine(origin, origin2);
			hyline.MakeUnBound();
			foreach (RadiatorConnParam radiatorConnParam in radiatorSet)
			{
				Connector connector = radiatorConnParam.InExPipeConn;
				if (style == 2)
				{
					connector = radiatorConnParam.OutExPipeConn;
				}
				if (connector != null)
				{
					XYZ origin3 = connector.Origin;
					XYZ project = hyline.GetProject(origin3);
					if (style == 1)
					{
						radiatorConnParam.PntOnPipeIn = project;
						radiatorConnParam.PntOnFaceIn = new XYZ(project.X, project.Y, origin3.Z);
					}
					if (style == 2)
					{
						radiatorConnParam.PntOnPipeOut = project;
						radiatorConnParam.PntOnFaceOut = new XYZ(project.X, project.Y, origin3.Z);
					}
					if (!hyline.IsPointOnLine(project))
					{
						double num = basePnt.DistanceTo(project);
						double num2 = xyz.DistanceTo(project);
						if (num > num2)
						{
							xyz = project;
						}
						else
						{
							basePnt = project;
						}
						hyline = new YJKLine(basePnt, xyz);
						hyline.MakeUnBound();
					}
				}
			}
			if (style == 2 && this.ConnStyle == 1)
			{
				this.returnPipe = hypiping.Extend(basePnt, xyz);
			}
			else
			{
				this.supplyPipe = hypiping.Extend(basePnt, xyz);
			}
			this.Doc.Regenerate();
			return true;
		}

		private List<RadiatorConnParam> InitialRadiatorParam(IList<FamilyInstance> radiators)
		{
			List<RadiatorConnParam> list = new List<RadiatorConnParam>();
			foreach (FamilyInstance familyInstance in radiators)
			{
				RadiatorConnParam radiatorConnParam = new RadiatorConnParam();
				radiatorConnParam.ElementId = familyInstance.Id.IntegerValue;
				radiatorConnParam.InExtend = UnitConvert.CovertToAPI(this.distanceSupply, (Autodesk.Revit.DB.DisplayUnitType)2);
				radiatorConnParam.OutExtend = UnitConvert.CovertToAPI(this.distanceReturn, (Autodesk.Revit.DB.DisplayUnitType)2);
				Connector inConnector = null;
				Connector outConnector = null;
				this.GetConnecctor(familyInstance, ref inConnector, ref outConnector);
				radiatorConnParam.InConnector = inConnector;
				radiatorConnParam.OutConnector = outConnector;
				list.Add(radiatorConnParam);
			}
			return list;
		}

		private void JudgeConnPosition(int elemId, ref bool inBeUp, ref bool outBeUp)
		{
			ElementId elementId = new ElementId(elemId);
			Parameter parameter = this.doc.GetElementById(elementId).GetParameter("HYRadiatorType");
			if (parameter == null)
			{
				return;
			}
			string text = parameter.AsString();
			uint num = 0;//<PrivateImplementationDetails>.ComputeStringHash(text);
			if (num <= 2279835011u)
			{
				if (num <= 518729469u)
				{
					if (num != 401286136u)
					{
						if (num != 501951850u)
						{
							if (num != 518729469u)
							{
								goto IL_1C2;
							}
							if (!(text == "13"))
							{
								goto IL_1C2;
							}
						}
						else
						{
							if (!(text == "12"))
							{
								goto IL_1C2;
							}
							goto IL_1B4;
						}
					}
					else if (!(text == "14"))
					{
						goto IL_1C2;
					}
				}
				else if (num != 2247118416u)
				{
					if (num != 2263057392u)
					{
						if (num != 2279835011u)
						{
							goto IL_1C2;
						}
						if (!(text == "42"))
						{
							goto IL_1C2;
						}
						goto IL_1AD;
					}
					else
					{
						if (!(text == "43"))
						{
							goto IL_1C2;
						}
						goto IL_1BB;
					}
				}
				else
				{
					if (!(text == "32"))
					{
						goto IL_1C2;
					}
					goto IL_1AD;
				}
			}
			else if (num <= 2314375987u)
			{
				if (num != 2296612630u)
				{
					if (num != 2297451273u)
					{
						if (num != 2314375987u)
						{
							goto IL_1C2;
						}
						if (!(text == "24"))
						{
							goto IL_1C2;
						}
					}
					else
					{
						if (!(text == "31"))
						{
							goto IL_1C2;
						}
						goto IL_1AD;
					}
				}
				else
				{
					if (!(text == "41"))
					{
						goto IL_1C2;
					}
					goto IL_1AD;
				}
			}
			else if (num != 2347784130u)
			{
				if (num != 2364708844u)
				{
					if (num != 2398264082u)
					{
						goto IL_1C2;
					}
					if (!(text == "23"))
					{
						goto IL_1C2;
					}
				}
				else
				{
					if (!(text == "21"))
					{
						goto IL_1C2;
					}
					goto IL_1B4;
				}
			}
			else
			{
				if (!(text == "34"))
				{
					goto IL_1C2;
				}
				goto IL_1BB;
			}
			inBeUp = true;
			outBeUp = false;
			return;
			IL_1AD:
			inBeUp = false;
			outBeUp = true;
			return;
			IL_1B4:
			inBeUp = true;
			outBeUp = true;
			return;
			IL_1BB:
			inBeUp = false;
			outBeUp = false;
			return;
			IL_1C2:
			inBeUp = true;
			outBeUp = false;
		}

		private RadiatorConnParam InitialRadiatorParam(FamilyInstance radiator)
		{
			RadiatorConnParam radiatorConnParam = new RadiatorConnParam();
			radiatorConnParam.ElementId = radiator.Id.IntegerValue;
			radiatorConnParam.InExtend = UnitConvert.CovertToAPI(this.distanceSupply, (Autodesk.Revit.DB.DisplayUnitType)2);
			radiatorConnParam.OutExtend = UnitConvert.CovertToAPI(this.distanceReturn, (Autodesk.Revit.DB.DisplayUnitType)2);
			Connector inConnector = null;
			Connector outConnector = null;
			this.GetConnecctor(radiator, ref inConnector, ref outConnector);
			radiatorConnParam.InConnector = inConnector;
			radiatorConnParam.OutConnector = outConnector;
			return radiatorConnParam;
		}

		private List<RadiatorConnParam> CreatLeadPipe(List<RadiatorConnParam> listConnParams)
		{
			List<RadiatorConnParam> list = new List<RadiatorConnParam>();
			foreach (RadiatorConnParam connParam in listConnParams)
			{
				RadiatorConnParam radiatorConnParam = this.CreatLeadPipe(connParam);
				if (radiatorConnParam != null)
				{
					list.Add(radiatorConnParam);
				}
			}
			return list;
		}

		private RadiatorConnParam CreatLeadPipe(RadiatorConnParam connParam)
		{
			Pipe pipe = null;
			Connector connector = null;
			if (this.SupplyPipe != null)
			{
				pipe = this.CreatRadiatorOutPipe(this.SupplyPipe, 1, connParam, ref connector);
				connParam.InPipe = pipe;
				connParam.InExPipeConn = connector;
			}
			if (this.ReturnPipe != null)
			{
				pipe = this.CreatRadiatorOutPipe(this.ReturnPipe, 2, connParam, ref connector);
				connParam.OutPipe = pipe;
				connParam.OutExPipeConn = connector;
			}
			if (this.ReturnPipe == null && this.SupplyPipe != null)
			{
				pipe = this.CreatRadiatorOutPipe(this.SupplyPipe, 2, connParam, ref connector);
				connParam.OutPipe = pipe;
				connParam.OutExPipeConn = connector;
			}
			if (pipe == null)
			{
				return null;
			}
			return connParam;
		}

		private Pipe CreatRadiatorOutPipe(Pipe basePipe, int connNum, RadiatorConnParam fcParam, ref Connector outConn)
		{
			Pipe pipe = null;
			XYZ xyz = null;
			List<FamilySymbol> list = new List<FamilySymbol>();
			if (connNum == 1 && fcParam.InConnector != null)
			{
				double diameter = fcParam.InConnector.Radius * 2.0;
				xyz = this.GetExtendPoint(fcParam.InConnector, fcParam.InExtend);
				pipe = YJKRevitTools.NewPipe(basePipe, fcParam.InConnector, xyz);
				this.SetDiameter(pipe, diameter);
				this.ConnPipeAndConnector(pipe, fcParam.InConnector);
				this.Doc.Regenerate();
				if (this.SymbolSupply != null)
				{
					list = new List<FamilySymbol>();
					list.Add(this.SymbolSupply);
					GroupValueManage groupValueManage = new GroupValueManage(this.Doc, pipe, fcParam.InConnector.Origin, 100.0, list);
					if (!groupValueManage.Go())
					{
						throw new Exception("阀件插入失败");
					}
					pipe = groupValueManage.GetEndPipe();
				}
			}
			else if (connNum == 2 && fcParam.OutConnector != null)
			{
				double diameter = fcParam.OutConnector.Radius * 2.0;
				xyz = this.GetExtendPoint(fcParam.OutConnector, fcParam.OutExtend);
				pipe = YJKRevitTools.NewPipe(basePipe, fcParam.OutConnector, xyz);
				this.SetDiameter(pipe, diameter);
				this.ConnPipeAndConnector(pipe, fcParam.OutConnector);
				this.Doc.Regenerate();
				if (this.SymbolReturn != null)
				{
					list = new List<FamilySymbol>();
					list.Add(this.SymbolReturn);
					GroupValueManage groupValueManage2 = new GroupValueManage(this.Doc, pipe, fcParam.OutConnector.Origin, 100.0, list);
					if (!groupValueManage2.Go())
					{
						throw new Exception("阀件插入失败");
					}
					pipe = groupValueManage2.GetEndPipe();
				}
			}
			this.doc.Regenerate();
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			double num = hypiping.StartConnector.Origin.DistanceTo(xyz);
			double num2 = hypiping.EndConnector.Origin.DistanceTo(xyz);
			outConn = ((num > num2) ? hypiping.EndConnector.Connector : hypiping.StartConnector.Connector);
			return pipe;
		}

		private XYZ GetExtendPoint(Connector conn, double extendLength)
		{
			XYZ origin = conn.Origin;
			XYZ basisZ = conn.CoordinateSystem.BasisZ;
			return origin.Add(basisZ * extendLength);
		}

		private bool ConnPipeAndConnector(Pipe pipe, Connector conn)
		{
			bool result = true;
			YJKPiping<Pipe> hypiping = new YJKPiping<Pipe>(pipe);
			double num = hypiping.StartConnector.Origin.DistanceTo(conn.Origin);
			double num2 = hypiping.EndConnector.Origin.DistanceTo(conn.Origin);
			((num > num2) ? hypiping.EndConnector.Connector : hypiping.StartConnector.Connector).ConnectTo(conn);
			return result;
		}

		private void SetDiameter(Pipe branchPipe, double diameter)
		{
			new YJKPiping<Pipe>(branchPipe).SetDiameter(diameter * 304.8);
		}

		private string ValidatingElements(List<Element> listElem)
		{
			string result = "";
			this.listRadiator = new List<FamilyInstance>();
			this.listPipe = new List<Pipe>();
			foreach (Element element in listElem)
			{
				int integerValue = element.Category.Id.IntegerValue;
				if (integerValue == -2008044)
				{
					this.listPipe.Add(element as Pipe);
				}
				if (integerValue == -2001140)
				{
					this.listRadiator.Add(element as FamilyInstance);
				}
			}
			if (this.listPipe.Count < 1)
			{
				if (this.ConnStyle == 1)
				{
					result = "选择的实体集合应该包含2根水管。";
				}
				else
				{
					result = "选择的实体集合应该包含1根水管。";
				}
			}
			else if (this.listPipe.Count == 1 && this.ConnStyle == 1)
			{
				result = "选择的实体集合应该包含2根水管。";
			}
			if (this.listRadiator.Count < 1)
			{
				result = "选择的实体集合应该包含1个散热器。";
			}
			return result;
		}

		public IList<FamilyInstance> ListRadiator
		{
			get
			{
				return this.listRadiator;
			}
			set
			{
				this.listRadiator = value;
			}
		}

		public IList<Pipe> ListPipe
		{
			get
			{
				return this.listPipe;
			}
			set
			{
				this.listPipe = value;
			}
		}

		public Pipe SupplyPipe
		{
			get
			{
				return this.supplyPipe;
			}
			set
			{
				this.supplyPipe = value;
			}
		}

		public Pipe ReturnPipe
		{
			get
			{
				return this.returnPipe;
			}
			set
			{
				this.returnPipe = value;
			}
		}

		public Document Doc
		{
			get
			{
				return this.doc;
			}
			set
			{
				this.doc = value;
			}
		}

		public Selection Sel
		{
			get
			{
				return this.sel;
			}
			set
			{
				this.sel = value;
			}
		}

		public FamilySymbol SymbolSupply
		{
			get
			{
				return this.symbolSupply;
			}
			set
			{
				this.symbolSupply = value;
			}
		}

		public FamilySymbol SymbolReturn
		{
			get
			{
				return this.symbolReturn;
			}
			set
			{
				this.symbolReturn = value;
			}
		}

		public double DistanceSupply
		{
			get
			{
				return this.distanceSupply;
			}
			set
			{
				this.distanceSupply = value;
			}
		}

		public double DistanceReturn
		{
			get
			{
				return this.distanceReturn;
			}
			set
			{
				this.distanceReturn = value;
			}
		}

		public int ConnStyle
		{
			get
			{
				return this.connStyle;
			}
			set
			{
				this.connStyle = value;
			}
		}

		public string Message
		{
			get
			{
				return this.message;
			}
			set
			{
				this.message = value;
			}
		}

		private IList<FamilyInstance> listRadiator;

		private IList<Pipe> listPipe;

		private Pipe supplyPipe;

		private Pipe returnPipe;

		private Document doc;

		private Selection sel;

		private FamilySymbol symbolSupply;

		private FamilySymbol symbolReturn;

		private double distanceSupply;

		private double distanceReturn;

		private int connStyle;

		private string message;
	}
}
